package com.didispace.autoconfiguration;

import java.util.List;

import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
import org.springframework.cloud.stream.binder.ExtendedProducerProperties;
import org.springframework.cloud.stream.binder.rabbit.RabbitConsumerProperties;
import org.springframework.cloud.stream.binder.rabbit.RabbitProducerProperties;

public class MyRabbitBinder extends MyRabbitMessageChannelBinder{

	
	List<MyRabbitMessageChannelBinder>binders;
	public MyRabbitBinder(ConnectionFactory connectionFactory, RabbitProperties rabbitProperties,
			List<MyRabbitMessageChannelBinder>binders) {
		super(connectionFactory, rabbitProperties);
		this.binders = binders;
		// TODO Auto-generated constructor stub
	}
	
	
	@Override
	public Queue createConsumerDestinationIfNecessary(String name, String group,
			ExtendedConsumerProperties<RabbitConsumerProperties> properties) {
		Queue queue = null ;
		for(MyRabbitMessageChannelBinder binder:binders){
			queue = binder.createConsumerDestinationIfNecessary(name, group, properties);
		}
		return queue;
	}
	
	@Override
	public Exchange createProducerDestinationIfNecessary(String name,
			ExtendedProducerProperties<RabbitProducerProperties> producerProperties) {
		Exchange exchange =null;
		for(MyRabbitMessageChannelBinder binder:binders){
			exchange = binder.createProducerDestinationIfNecessary(name, producerProperties);
		}
		return exchange;
	}

}
